<template>
  <div>
    <div
      class="item-box"
      v-for="(item, index) in list"
      :key="index"
      :class="{ active:item.checked ,}"
      @click="selectMaterial(item,index)"
    >
      <div class="left">
        <!-- <van-checkbox icon-size="14px" v-model="item.checked" shape="square" :disabled="checkedDisable(item)"></van-checkbox> -->
      </div>
      <div class="right">
        <div class="header">
          <span class="name" v-if="item.materialFields">{{
            item.materialFields.name
          }}</span>
        </div>
        <div class="content">
          <div class="line flex">
            <div class="info">
              <span class="name">物料编码:</span>
              <span class="val" v-if="item.materialFields">{{
                item.materialFields.code
              }}</span>
            </div>
          </div>

          <div class="line flex">
            <div class="info">
              <span class="name">特征参数:</span>
              <span class="val">{{ item.skuName }}</span>
            </div>
          </div>
          <div class="line flex">
            <div class="info">
              <span class="name">批次号:</span>
              <span class="val">{{ item.barCode }}</span>
            </div>
          </div>
          <div class="line flex">
            <div class="info">
              <span class="name">库区名称:</span>
              <span class="val">{{ item.stockLocationName }}</span>
            </div>
          </div>
          <div class="line flex">
            <div class="info">
              <span class="name">库位名称:</span>
              <span class="val">{{ item.goodsShelvesName }}</span>
            </div>
          </div>
          <div class="line flex">
            <div class="info">
              <span class="name">库存数量:</span>
              <span class="val">{{ item.stockLocationQuantity }}</span>
            </div>
            <div class="info">
              <span class="name">批次品质:</span>
              <span class="val">{{ item.materialQualityName }}</span>
            </div>
          </div>
          <div class="line">
            <div class="info">
              <span class="name">批次备注:</span>
              <span class="val">{{ item.remark }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
// import MaterialContent from "./MaterialContent.vue";
export default {
  name: "ListItem",
  components: {
    // MaterialContent,
  },
  props: {
    list: {
      type: Array,
      default: () => [],
      required: true,
    },
  },
  data() {
    return {
      current: null,
      // isShow: false,
    };
  },
  methods: {
    selectMaterial(item,index) {
      // if(this.checkedDisable(item)){
      //   return
      // }
      this.list.map(i=>{
        i.checked = false
      })
      item.checked = true
      // const id = this.list[index].inventoryDetailId
      // const arr = JSON.parse(localStorage.getItem('selectIds'))   
      // if(!arr.includes(id)){
      //   // this.list[index].checked = !this.list[index].checked
      //   // this.$emit("selectMaterial", this.list[index]);
      // }
    },
    checkedDisable(item){
        const id = item.inventoryDetailId
        const arr = JSON.parse(localStorage.getItem('selectIds')) ||[]
        console.log('arr.includes(id)',arr.includes(id),arr,id)
        return arr.includes(id)
    },
  },
};
</script>

<style lang="scss" scoped>
.item-box {
  display: flex;
  margin: 0 0 12px;
  background-color: #ffffff;
  border-radius: 4px;
  box-shadow: 0px 3px 6px 1px rgba(0, 0, 0, 0.16);
  padding: 12px;
  font-size: 14px;
  color: #333333;
  border: 1px #ffffff solid;
  .left{
    margin-right: 10px;
  }
  &.active {
    border: 1px #548af1 solid;
    position: relative;
    &::after {
      content: "";
      width: 4px;
      height: 100%;
      background-color: #548af1;
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
    }
  }
  &.disabled{
    position: relative;
    border:1px solid #c1c2c4;
    &::after {
      content: "";
      width: 4px;
      height: 100%;
      background-color: #c1c2c4;
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
    }
  }
  .header {
    .no {
      margin: 0 4px;
    }
  }
  .content {
    padding-top: 5px;
    .line {
      margin-top: 10px;
      .name {
        color: #666666;
      }
    }
    .flex {
      display: flex;
      justify-content: space-between;
    }
  }
  .right{
    flex: 1;
  }
}
</style>